//
//  StartCityTableViewController.m
//  We_Travel
//
//  Created by lanou3g on 15/12/15.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "StartCityTableViewController.h"
#import "City.h"

@interface StartCityTableViewController ()
@property (nonatomic , strong) NSMutableArray *dataArray;
@end

@implementation StartCityTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if([self.str isEqualToString:@"起始"]){
        self.title = @"出发城市";
    }else if ([self.str isEqualToString:@"结束"]){
        self.title = @"到达城市";
    }
    [self setupNavigation];
    [self loadData];
}
- (void)setupNavigation{
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"back.png"] style:UIBarButtonItemStyleDone target:self action:@selector(leftBarButtonItemAction:)];
    self.navigationController.navigationBar.barTintColor = [UIColor cyanColor];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
}
- (void)leftBarButtonItemAction:(UIBarButtonItem *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)loadData
{
    City *c0 = [[City alloc] initWithName:@"北京"];
    City *c1 = [[City alloc] initWithName:@"上海"];
    City *c2 = [[City alloc] initWithName:@"广州"];
    City *c3 = [[City alloc] initWithName:@"深圳"];
    City *c4 = [[City alloc] initWithName:@"天津"];
    City *c5 = [[City alloc] initWithName:@"武汉"];
    City *c6 = [[City alloc] initWithName:@"大连"];
    City *c7 = [[City alloc] initWithName:@"重庆"];
    City *c8 = [[City alloc] initWithName:@"成都"];
    City *c9 = [[City alloc] initWithName:@"南京"];
    City *c10 = [[City alloc] initWithName:@"杭州"];
    City *c11 = [[City alloc] initWithName:@"长沙"];
    City *c12 = [[City alloc] initWithName:@"西安"];
    City *c13 = [[City alloc] initWithName:@"青岛"];
    City *c14 = [[City alloc] initWithName:@"石家庄"];
    City *c15 = [[City alloc] initWithName:@"太原"];
    City *c16 = [[City alloc] initWithName:@"沈阳"];
    City *c17 = [[City alloc] initWithName:@"长春"];
    City *c18 = [[City alloc] initWithName:@"哈尔滨"];
    City *c19 = [[City alloc] initWithName:@"合肥"];
    City *c20 = [[City alloc] initWithName:@"福州"];
    City *c21 = [[City alloc] initWithName:@"南昌"];
    City *c22 = [[City alloc] initWithName:@"济南"];
    City *c23 = [[City alloc] initWithName:@"郑州"];
    City *c24 = [[City alloc] initWithName:@"宁波"];
    City *c25 = [[City alloc] initWithName:@"海口"];
    City *c26 = [[City alloc] initWithName:@"贵阳"];
    City *c27 = [[City alloc] initWithName:@"昆明"];
    City *c28 = [[City alloc] initWithName:@"烟台"];
    City *c29 = [[City alloc] initWithName:@"兰州"];
    City *c30 = [[City alloc] initWithName:@"西宁"];
    City *c31 = [[City alloc] initWithName:@"拉萨"];
    City *c32 = [[City alloc] initWithName:@"南宁"];
    City *c33 = [[City alloc] initWithName:@"呼和浩特"];
    City *c34 = [[City alloc] initWithName:@"银川"];
    City *c35 = [[City alloc] initWithName:@"乌鲁木齐"];
    City *c36 = [[City alloc] initWithName:@"香港"];
    City *c37 = [[City alloc] initWithName:@"澳门"];
    City *c38 = [[City alloc] initWithName:@"台北"];
    City *c39 = [[City alloc] initWithName:@"潮州市"];
    City *c40 = [[City alloc] initWithName:@"揭阳市"];
    City *c41 = [[City alloc] initWithName:@"汕头"];
    City *c42 = [[City alloc] initWithName:@"桂林"];
    City *c43 = [[City alloc] initWithName:@"厦门"];
    
    [self.dataArray addObject:c0];
    [self.dataArray addObject:c1];
    [self.dataArray addObject:c2];
    [self.dataArray addObject:c3];
    [self.dataArray addObject:c4];
    [self.dataArray addObject:c5];
    [self.dataArray addObject:c6];
    [self.dataArray addObject:c7];
    [self.dataArray addObject:c8];
    [self.dataArray addObject:c9];
    [self.dataArray addObject:c10];
    [self.dataArray addObject:c11];
    [self.dataArray addObject:c12];
    [self.dataArray addObject:c13];
    [self.dataArray addObject:c14];
    [self.dataArray addObject:c15];
    [self.dataArray addObject:c16];
    [self.dataArray addObject:c17];
    [self.dataArray addObject:c18];
    [self.dataArray addObject:c19];
    [self.dataArray addObject:c20];
    [self.dataArray addObject:c21];
    [self.dataArray addObject:c22];
    [self.dataArray addObject:c23];
    [self.dataArray addObject:c24];
    [self.dataArray addObject:c25];
    [self.dataArray addObject:c26];
    [self.dataArray addObject:c27];
    [self.dataArray addObject:c28];
    [self.dataArray addObject:c29];
    [self.dataArray addObject:c30];
    [self.dataArray addObject:c31];
    [self.dataArray addObject:c32];
    [self.dataArray addObject:c33];
    [self.dataArray addObject:c34];
    [self.dataArray addObject:c35];
    [self.dataArray addObject:c36];
    [self.dataArray addObject:c37];
    [self.dataArray addObject:c38];
    [self.dataArray addObject:c39];
    [self.dataArray addObject:c40];
    [self.dataArray addObject:c41];
    [self.dataArray addObject:c42];
    [self.dataArray addObject:c43];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSMutableArray *)dataArray
{
    if (_dataArray == nil) {
        self.dataArray = [NSMutableArray array];
    }
    return _dataArray;
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.dataArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"start"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"start"];
    }
    City *c = self.dataArray[indexPath.row];
    cell.textLabel.text = c.name;
    cell.imageView.image = [UIImage imageNamed:@"xuanzhong"];
    cell.imageView.hidden = !c.isSelected;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    City *c = self.dataArray[indexPath.row];
    if (c.isSelected) {
        return;
    }else{
        c.isSelected = YES;
        self.block(c.name);
        [self.navigationController popViewControllerAnimated:YES];
    }
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
